<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 搜索条件
const doctorName = ref('')
const department = ref('')
const dateRange = ref('')

// 表格数据
const tableData = ref([
  {
    id: 1,
    name: '张华明',
    gender: '男',
    age: 36,
    type: '初诊',
    department: '普外科',
    status: '等待中',
    appointmentTime: '2024/04/04 08:15'
  },
  {
    id: 2,
    name: '周明明',
    gender: '女',
    age: 19,
    type: '初诊',
    department: '内科',
    status: '等待中',
    appointmentTime: '2024/04/04 08:15'
  }
])

// 分页
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

// 处理分页变化
const handleCurrentChange = (val: number) => {
  currentPage.value = val
}

// 处理每页显示条数变化
const handleSizeChange = (val: number) => {
  pageSize.value = val
}

// 处理详情
const handleDetail = (row: any) => {
  router.push({
    path: `/doctor/patient-detail/${row.id}`,
    query: { ...row }
  })
}

// 处理编辑
const handleEdit = (row: any) => {
  console.log('编辑', row)
}

// 处理删除
const handleDelete = (row: any) => {
  console.log('删除', row)
}
</script>

<template>
  <div class="patient-list">
    <!-- 搜索区域 -->
    <div class="search-section">
      <el-form :inline="true">
        <el-form-item label="接诊医生">
          <el-input v-model="doctorName" placeholder="请输入医生姓名" />
        </el-form-item>
        <el-form-item label="科室">
          <el-select v-model="department" placeholder="请选择科室">
            <el-option label="全部" value="" />
            <el-option label="内科" value="内科" />
            <el-option label="外科" value="外科" />
            <el-option label="儿科" value="儿科" />
          </el-select>
        </el-form-item>
        <el-form-item label="日期">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary">搜索</el-button>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格区域 -->
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="gender" label="性别" width="80" />
      <el-table-column prop="age" label="年龄" width="80" />
      <el-table-column prop="type" label="门诊类型" width="100">
        <template #default="{ row }">
          <el-tag :type="row.type === '初诊' ? 'primary' : 'success'">{{ row.type }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="department" label="科室" width="100" />
      <el-table-column prop="appointmentTime" label="预约时间" width="160" />
      <el-table-column prop="status" label="状态" width="100">
        <template #default="{ row }">
          <el-tag :type="row.status === '等待中' ? 'warning' : 'success'">{{ row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" fixed="right">
        <template #default="{ row }">
          <el-button size="small" @click="handleDetail(row)">详情</el-button>
          <el-button size="small" type="primary" @click="handleEdit(row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 50]"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
.patient-list {
  padding: 20px;

  .search-section {
    background: #f5f7fa;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
  }

  :deep(.el-table) {
    background: #f5f7fa;
    border-radius: 12px;
    overflow: hidden;
  }

  .pagination {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    background: #f5f7fa;
    padding: 20px;
    border-radius: 12px;
  }
}
</style>